package com.example.peibei.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.dingtao.common.bean.User;
import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDFragment;
import com.dingtao.common.core.exception.ApiException;
import com.dingtao.common.util.SPUtils;
import com.example.peibei.R;
import com.example.peibei.base.SpConstant;
import com.example.peibei.service.presenter.GetOtherUserInfoPresenter;
import com.example.peibei.ui.activity.PersonalInfoActivity;
import com.example.peibei.ui.utils.LevelImage;

import butterknife.BindView;

public class AuthenticationFragment extends WDFragment {
    @BindView(R.id.iv_sm)
    ImageView iv_sm;
    @BindView(R.id.iv_phone)
    ImageView iv_phone;
    @BindView(R.id.iv_zr)
    ImageView iv_zr;
    @BindView(R.id.tv_sm)
    TextView tv_sm;
    @BindView(R.id.tv_phone)
    TextView tv_phone;
    @BindView(R.id.tv_zr)
    TextView tv_zr;

    private GetOtherUserInfoPresenter getOtherUserInfoPresenter;
    private SPUtils spUtils;
    private String token;
    private String mid;
    private String mymid;

    public AuthenticationFragment(String mid) {
        this.mid = mid;
    }

    @Override
    public String getPageName() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_authentication;
    }

    @Override
    protected void initView() {
        spUtils = new SPUtils(getActivity(), SpConstant.USER_TOKEN);
        token = spUtils.getString(SpConstant.USER_TOKEN);
        mymid = spUtils.getLong(SpConstant.USER_MID) + "";
        getOtherUserInfoPresenter = new GetOtherUserInfoPresenter(new UserInfoCall());
        getOtherUserInfoPresenter.reqeust(mid, mymid);
    }

    class UserInfoCall implements DataCall<User> {

        @Override
        public void success(User data, Object... args) {
            if (data.isIdentity()) {
                tv_sm.setText("实名已认证");
                iv_sm.setBackgroundResource(R.mipmap.shimingrenzheng);
                tv_sm.setTextColor(getResources().getColor(R.color.gray_home));
            } else {
                tv_sm.setText("实名未认证");
                iv_sm.setBackgroundResource(R.mipmap.shimingrenzheng_no);
                tv_sm.setTextColor(getResources().getColor(R.color.color_9C9DA1));
            }
            if (!TextUtils.isEmpty(data.getMobile())) {
                tv_phone.setText("手机已认证");
                iv_phone.setBackgroundResource(R.mipmap.shoujirenzheng);
                tv_phone.setTextColor(getResources().getColor(R.color.gray_home));
            } else {
                tv_phone.setText("手机未认证");
                iv_phone.setBackgroundResource(R.mipmap.shoujirenzheng_no);
                tv_phone.setTextColor(getResources().getColor(R.color.color_9C9DA1));
            }
            if (!TextUtils.isEmpty(data.getMobile())) {
                tv_zr.setText("真人已认证");
                iv_zr.setBackgroundResource(R.mipmap.zhenrenrenzheng);
                tv_zr.setTextColor(getResources().getColor(R.color.gray_home));
            } else {
                tv_zr.setText("真人未认证");
                iv_zr.setBackgroundResource(R.mipmap.zhenrenrenzheng_no);
                tv_zr.setTextColor(getResources().getColor(R.color.color_9C9DA1));
            }

        }

        @Override
        public void fail(ApiException e, Object... args) {

        }
    }
}

